<template>
	
	<view class="con">
		<CustomNavbar></CustomNavbar>
		<view class="icont">
			<view class="swiper">
				<u-swiper
					:list="list.banner"
					keyName="banner_path"
					@change="e => currentOne = e.current"
					:autoplay="true"
					height="600"
					>
					<view slot="indicator" class="indicator">
						<view class="indicator__dot"
							v-for="(item, index) in list.banner"
							:key="index"
							:class="[index === currentOne && 'indicator__dot--active']"
						>
						</view>
					</view>
				</u-swiper>
			</view>
			<view class="etncIimg">
				<image :src="list.cate_detail.mall_img_url" mode="widthFix"></image>
			</view>
			<view class="etncText">下单更优惠</view>
			<view class="etncList">
				<view class="etncListli" v-for="(item, index) in list.recommend_cate">
					<view class="etncListliTop">
						<image :src="item.mall_img_url"></image>
					</view>
					<view class="goodsCont">
						<view class="goodsContli" v-for="(v, i) in item.product">
							<view class="goodsContliImg" @click="ontype(v)">
								<image :src="v.preview_img" mode="widthFix"></image>
							</view>
							
							<view class="goodsContliText" @click="ontype(v)">{{v.product_name}}</view>
							<!-- <view class="goodsContliTs" @click="ontype(v)">
								<text>会员券后价</text>
								<text>包邮</text>
							</view> -->
							<view class="goodsContliCz" @click="ontype(v)">
								<view class="goodsMoney"><text>¥</text>{{v.shop_price}}</view>
								
							</view>
							<view class="buy" @click="onGwc(v)">
								<image src="https://img-cdn.duobashuzi.com/xianggui/img/gwc_h.png" mode="scaleToFill"></image>
								<!-- <text class="num" v-if="v.mum">{{v.mum}}</text> -->
							</view>
						</view>
						
					</view>
				</view>
			</view>
		</view>
		<view class="richtext">
			<rich-text :imgOptions="imgOptions" :nodes="processedContent"></rich-text>
		</view>
		<side-bar></side-bar>
		<sheet-bottom ref="getSpecList" :isCart="isCart" @goodsId="jianting" :isSheet.sync="isSheet" :goodsInfo.sync="goodsInfo" @closeSheet="closeShee"></sheet-bottom>
	</view>

</template>

<script>
	import{etncData,djgfData} from '@/api/levelTwo.js'
	import{goodsDetail} from '@/api/index.js'
	import sideBar from "@/components/sheet/sideBar.vue"
	import CustomNavbar from "@/components/CustomNavbar.vue"
	import sheetBottom from "@/components/sheet/sheetBottom.vue"
	export default {
		data() {
			return {
				list:{},
				currentOne:0,
				goodsInfo:'',
				isCart:0,
				isSheet:false,
				banner_id:'',
				cate_id:'',
				processedContent:'',
				imgOptions: {
					mode: 'aspectFit', // 图片显示模式
					ignore: true // 禁用默认的图片预览行为
				},
				phoneNumber:''//客服电话
			}
		},
		components: {
			sideBar,
			sheetBottom,
			CustomNavbar
		},
		onLoad(options) {
			console.log(options)
			this.banner_id = options.banner_id;
			this.cate_id =options. cate_id
			let custom = uni.getMenuButtonBoundingClientRect(); // 小程序右上角胶囊信息
			let system = uni.getSystemInfoSync(); // 获取设备信息
			this.navHeight = system.statusBarHeight + 44; // 导航栏的高度
			this.customTop = custom.top; // 胶囊按钮与顶部的距离
			this.customHeight = custom.height; // 胶囊按钮与右侧的距离
			
			this.gettopCate();
			
		},
		methods: {
			
			gettopCate(){
				
				let data = {
					banner_id:this.banner_id,
					cate_id:this.cate_id
				}
				etncData(data).then(res => {
					console.log(res)
					 this.list = res.data;
					this.processedContent = this.list.cate_detail.content.replace(
					            /<img /g,
					            '<img style="width:100%;height:auto;" '
					        );
				}).catch(err => {
					uni.showToast({
						title: err.msg,
						icon: "none"
					})
				})
			},
			//商品的跳转
			ontype(e){
				console.log(e)
			// let data = this.baseList[e];
				uni.navigateTo({
					url: '/package/info/index?id='+e.id+'&title='+e.product_name
				});
			},
			//打开购买弹窗
			onGwc(e){
				console.log()
				goodsDetail({
					goods_id: e.id
				}).then(res => {
					console.log(res)
					this.isSheet = true;
					this.goodsInfo = res.result;
					if(this.goodsInfo.is_spec == 1){
						this.$nextTick(()=>{
							this.$refs.getSpecList.getgoodsSpecList();
						})
					}
				}).catch(err => {
					uni.showToast({
						title: err.msg,
						icon: "none"
					})
				})
				
				console.log(this.goodsInfo)
				// this.$set(e,"goods_num",0)
			},
			//监听加入购物车成功
			jianting(e){
				this.twolit.forEach((v,i)=>{
					if(v.id == e.id){
						
						v.mum = e.minimum_order_quantity;
					}
				});
			},
			//关闭购物车
			closeShee(e){
				this.isSheet = e
			}
		}
	}
</script>

<style lang="scss">
	
	@import 'index.scss';
</style>